import {message} from 'antd';
import {formatMessage} from './intl';

export const newOrUpdateOrderValidator = data => {
    //增加判断必填字段
    const emptyErrors = [];
    if(!data.id && (!data || !data.brandId))
        emptyErrors.push(formatMessage({
            id: 'validator.empty.brandId',
            defaultMessage: '品牌'
        }));
    if(!data.id && (!data || !data.dealerId))
        emptyErrors.push(formatMessage({
            id: 'validator.empty.dealerId',
            defaultMessage: '总代'
        }));
    if(!data || !data.issueCountryId)
        emptyErrors.push(formatMessage({
            id: 'validator.empty.issueCountryId',
            defaultMessage: '开证国家'
        }));
    if(!data || !data.issueBank)
        emptyErrors.push(formatMessage({
            id: 'validator.empty.issueBank',
            defaultMessage: '开证银行'
        }));
    if(!data || !data.issuePrice)
        emptyErrors.push(formatMessage({
            id: 'validator.empty.issuePrice',
            defaultMessage: '开证金额'
        }));
    if(!data || !data.lcPayMentDays)
        emptyErrors.push(formatMessage({
            id: 'validator.empty.lcPayMentDays',
            defaultMessage: '信用证账期'
        }));
    if(!data || !data.currency)
        emptyErrors.push(formatMessage({
            id: 'validator.empty.currency',
            defaultMessage: '币种'
        }));
    if(!data || !data.issueDate)
        emptyErrors.push(formatMessage({
            id: 'validator.empty.issueDate',
            defaultMessage: '开证日期'
        }));
    if(!data || (!data.isAllowBatch && typeof data.isAllowBatch !== 'number'))
        emptyErrors.push(formatMessage({
            id: 'validator.empty.isAllowBatch',
            defaultMessage: '是否允许分批'
        }));
    if(!data || !data.dateOfExpiry)
        emptyErrors.push(formatMessage({
            id: 'validator.empty.dateOfExpiry',
            defaultMessage: '效期'
        }));
    if(!data.id && (!data || !data.lcKind))
        emptyErrors.push(formatMessage({
            id: 'validator.empty.lcKind',
            defaultMessage: '信用证类型'
        }));
    if(!data || !data.lcOfficialDraftType)
        emptyErrors.push(formatMessage({
            id: 'validator.empty.lcOfficialDraftType',
            defaultMessage: '正本草本'
        }));
    if(emptyErrors.length > 0) {
        message.warning(`${emptyErrors.join('，')}${formatMessage({
            id: 'validator.required',
            defaultMessage: '必填！'
        })}`);
        return false;
    }
    return true;
};

export const receiveOrderValidator = details => {
    const requiredFields = [];
    if(details.some(d => !d.cashInPrice))
        requiredFields.push(
            formatMessage({
                id: 'validator.cashInPrice',
                defaultMessage: '到款金额'
            }));
    if(details.some(d => !d.cashInDate))
        requiredFields.push(
            formatMessage({
                id: 'validator.cashInDate',
                defaultMessage: '到款日期'
            }));
    if(requiredFields.length > 0) {
        message.warning(`${requiredFields.join('，')}${formatMessage({
            id: 'validator.required',
            defaultMessage: '必填！'
        })}`);
        return false;
    }
    return true;
};

export const approveValidator = data => {
    //增加判断必填字段
    const emptyErrors = [];
    if(!data || !data.issuePriceIsApprove)
        emptyErrors.push(formatMessage({
            id: 'validator.empty.issuePriceIsApprove',
            defaultMessage: '开证金额'
        }));
    if(!data || !data.shippingPortIsApprove)
        emptyErrors.push(formatMessage({
            id: 'validator.empty.shippingPortIsApprove',
            defaultMessage: '发货港'
        }));
    if(!data || !data.destinationPortIsApprove)
        emptyErrors.push(formatMessage({
            id: 'validator.empty.destinationPortIsApprove',
            defaultMessage: '目的港'
        }));
    if(!data || !data.lastLoadDateIsApprove)
        emptyErrors.push(formatMessage({
            id: 'validator.empty.lastLoadDateIsApprove',
            defaultMessage: '最迟装船日期'
        }));
    if(!data || !data.dateOfExpiryIsApprove)
        emptyErrors.push(formatMessage({
            id: 'validator.empty.dateOfExpiryIsApprove',
            defaultMessage: '效期'
        }));
    if(!data || !data.placeOfExpiryIsApprove)
        emptyErrors.push(formatMessage({
            id: 'validator.empty.placeOfExpiryIsApprove',
            defaultMessage: '效地'
        }));
    if(!data || !data.lcPayMentDaysMarketDepartmentIsApprove)
        emptyErrors.push(formatMessage({
            id: 'validator.empty.lcPayMentDaysMarketDepartmentIsApprove',
            defaultMessage: '信用证账期'
        }));
    if(!data || !data.commodityDescriptionIsApprove)
        emptyErrors.push(formatMessage({
            id: 'validator.empty.commodityDescriptionIsApprove',
            defaultMessage: '货描'
        }));
    if(emptyErrors.length > 0) {
        message.warning(`${emptyErrors.join('，')}${formatMessage({
            id: 'validator.required1',
            defaultMessage: '审核必选！'
        })}`);
        return false;
    }
    return true;
};

export const financeValidator = data => {
    //增加判断必填字段
    const emptyErrors = [];
    if(!data || !data.issueBankIsApprove)
        emptyErrors.push(formatMessage({
            id: 'validator.empty.issueBankIsApprove',
            defaultMessage: '开证银行'
        }));
    if(!data || !data.lcKindIsApprove)
        emptyErrors.push(formatMessage({
            id: 'validator.empty.lcKindIsApprove',
            defaultMessage: '信用证类型'
        }));
    if(!data || !data.lcPayMentDaysFinanceIsApprove)
        emptyErrors.push(formatMessage({
            id: 'validator.empty.lcPayMentDaysFinanceIsApprove',
            defaultMessage: '信用证账期'
        }));
    if(emptyErrors.length > 0) {
        message.warning(`${emptyErrors.join('，')}${formatMessage({
            id: 'validator.required1',
            defaultMessage: '审核必选！'
        })}`);
        return false;
    }
    return true;
};

export const draftValidator = data => {
    //增加判断必填字段
    const emptyErrors = [];
    if(!data || !data.lcCode)
        emptyErrors.push(formatMessage({
            id: 'validator.empty.lcCode',
            defaultMessage: '信用证号码'
        }));
    if(!data || !data.issueCountryId)
        emptyErrors.push(formatMessage({
            id: 'validator.empty.issueCountryId',
            defaultMessage: '开证国家'
        }));
    if(!data || !data.issueBank)
        emptyErrors.push(formatMessage({
            id: 'validator.empty.issueBank',
            defaultMessage: '开证银行'
        }));
    if(!data || !data.issuePrice)
        emptyErrors.push(formatMessage({
            id: 'validator.empty.issuePrice',
            defaultMessage: '开证金额'
        }));
    if(!data || !data.lcPayMentDays)
        emptyErrors.push(formatMessage({
            id: 'validator.empty.lcPayMentDays',
            defaultMessage: '信用证账期'
        }));
    if(!data || !data.currency)
        emptyErrors.push(formatMessage({
            id: 'validator.empty.currency',
            defaultMessage: '币种'
        }));
    if(!data || !data.issueDate)
        emptyErrors.push(formatMessage({
            id: 'validator.empty.issueDate',
            defaultMessage: '开证日期'
        }));
    if(!data || (!data.isAllowBatch && typeof data.isAllowBatch !== 'number'))
        emptyErrors.push(formatMessage({
            id: 'validator.empty.isAllowBatch',
            defaultMessage: '是否允许分批'
        }));
    if(!data || !data.dateOfExpiry)
        emptyErrors.push(formatMessage({
            id: 'validator.empty.dateOfExpiry',
            defaultMessage: '效期'
        }));
    if(emptyErrors.length > 0) {
        message.warning(`${emptyErrors.join('，')}${formatMessage({
            id: 'validator.required',
            defaultMessage: '必填！'
        })}`);
        return false;
    }
    return true;
};

export const approveRejectValidator = data => {
    //增加判断必填字段
    const emptyErrors = [];
    if(!data || !data.approveComment)
        emptyErrors.push(formatMessage({
            id: 'validator.empty.approveComment',
            defaultMessage: '审核意见'
        }));
    if(emptyErrors.length > 0) {
        message.warning(`${emptyErrors.join('，')}${formatMessage({
            id: 'validator.required',
            defaultMessage: '必填！'
        })}`);
        return false;
    }
    return true;
};
